using System;
using UnityEngine;

public class SettlementUIManager : MonoBehaviour
{
	private SettlementWindow m_FocusSettlementWindow;

	[SerializeField]
	private SettlementGameover m_GameOverUI;

	[SerializeField]
	private SettlementQuickFireWin m_QuickFireWinUI;

	[SerializeField]
	private SettlementQuickFireLose m_QuickFireLoseUI;

	[SerializeField]
	private SettlementMissionComplete m_MissionCompleteUI;

	[SerializeField]
	private SettlementMissionFail m_MissionFailUI;

	[SerializeField]
	private SettlementStandardGameover m_StandardGameoverUI;

	[SerializeField]
	private Animator m_Animator;

	public bool WindowOpen()
	{
		return m_FocusSettlementWindow != null;
	}

	public void Back()
	{
		m_FocusSettlementWindow.OnBack();
	}

	public void QuickWin(QuickFirePlayer.PlayerData playerData)
	{
		Advertising.PopIngameAd();
		m_Animator.SetTrigger("QuickWin");
		m_FocusSettlementWindow = m_QuickFireWinUI;
	}

	public void QuickLose(QuickFirePlayer.PlayerData playerData)
	{
		Advertising.PopIngameAd();
		m_Animator.SetTrigger("QuickLose");
		m_FocusSettlementWindow = m_QuickFireLoseUI;
	}

	public void GameOver(QuickFirePlayer.PlayerData playerData)
	{
		Advertising.PopIngameAd();
		m_GameOverUI.gameObject.SetActive(value: true);
		m_GameOverUI.SetData(playerData);
		m_FocusSettlementWindow = m_GameOverUI;
	}

	public void MissionComplete(MissionPlayer.PlayerData playerData)
	{
		m_MissionCompleteUI.SetData(playerData, isWin: true);
		m_MissionCompleteUI.gameObject.SetActive(value: true);
		m_FocusSettlementWindow = m_MissionCompleteUI;
		NewBie.instance.enable = false;
	}

	public void MissionFail(MissionPlayer.PlayerData playerData)
	{
		m_MissionCompleteUI.SetData(playerData, isWin: false);
		m_MissionCompleteUI.gameObject.SetActive(value: true);
		m_FocusSettlementWindow = m_MissionCompleteUI;
	}

	private bool OpenRateDialog()
	{
		/* if (!PlayerPrefs.HasKey("StarRateKey"))
		{
			UIADViewWnd.Show(UIADViewWnd.ADViewType.Rate);
			return true;
		} */
		return false;
	}

	public void StandardGameOver(BasePlayer player, BasePlayer oppentPlayer)
	{
		Action action = delegate
		{
			BattleInfo curBattleInfo = AIPlayer.curBattleInfo;
			bool flag = false;
			if (player is AIPlayer)
			{
				UnityEngine.Debug.Log("AI Player Win!");
				flag = false;
				if (curBattleInfo == null)
				{
				}
			}
			else
			{
				flag = true;
				if (curBattleInfo != null)
				{
					ConstantData.chips += curBattleInfo.chips;
					BattleInfoMgr.UnlockNextLevel(curBattleInfo.id);
				}
			}
			m_StandardGameoverUI.gameObject.SetActive(value: true);
			m_StandardGameoverUI.SetWinner(curBattleInfo.chips, flag, (!flag) ? player.playerName.text : oppentPlayer.playerName.text);
			m_FocusSettlementWindow = m_StandardGameoverUI;
		};
		if (!(player is AIPlayer) && OpenRateDialog())
		{
			UIADViewWnd.OnRateThisAppDestroy = action;
			return;
		}
		Advertising.PopIngameAd();
		action();
	}
}
